﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Stp.Core.Services
{
    public class AccountRegisterService : ServiceBase
    {
        private IAccount _account;

        public AccountRegisterService(AccountModel acModel) : this(new Account(acModel)) { }

        public AccountRegisterService(IAccount account)
        {
            _account = account;
        }

        public override ActionResult Execute()
        {
            try
            {
                bool successful = _account.VerifyData();
                if (successful)
                {
                    _account.Register();
                    BuildActionResult(true, string.Empty);
                }
                else
                {
                    BuildActionResult(false, "Account data is not valid.");
                }
            }
            catch (Exception ex)
            {
                BuildActionResult(false, ex.Message);
            }

            return _aResult;
        }
    }
}
